package com.yang.entity;

import javax.persistence.CascadeType;
import javax.persistence.Column;
import javax.persistence.Entity;
import javax.persistence.FetchType;
import javax.persistence.GeneratedValue;
import javax.persistence.Id;
import javax.persistence.JoinColumn;
import javax.persistence.ManyToOne;
import javax.persistence.Table;
import javax.persistence.Transient;
import org.codehaus.jackson.annotate.JsonIgnore;
import org.hibernate.annotations.GenericGenerator;

/**
 * 描述：权限实体
 * 版本：1.0
 * 作者： 杨建全
 * 创建时间：2016年3月24日  上午10:25:03
 */
@Entity
@Table(name = "t_permissions")
public class Permissions {
	
	private String id;				//权限id
	private String name;			//权限名称
	private String pCode;			//权限码
	private String parentId;		//父id
	
	private boolean checked;		//是否勾选	非数据库存储数据，只是前端显示用
	
	
	private Roles role;	
	
	@Id
	@GeneratedValue(generator = "uuid")
    @GenericGenerator(name = "uuid", strategy = "uuid")
	@Column(name = "pid", nullable = false, length = 9)
	public String getId() {
		return id;
	}
	
	public void setId(String id) {
		this.id = id;
	}
	
	public String getName() {
		return name;
	}

	public void setName(String name) {
		this.name = name;
	}

	@Column(name = "p_code", nullable = false)
	public String getpCode() {
		return pCode;
	}
	public void setpCode(String pCode) {
		this.pCode = pCode;
	}
	@Column(name = "parentId")
	public String getParentId() {
		return parentId;
	}
	public void setParentId(String parentId) {
		this.parentId = parentId;
	}
	@JsonIgnore
	@ManyToOne(cascade = {CascadeType.ALL},fetch=FetchType.LAZY)
	@JoinColumn(name="role_id")
	public Roles getRole() {
		return role;
	}
	public void setRole(Roles role) {
		this.role = role;
	}
	
	@Transient
	public boolean isChecked() {
		return checked;
	}

	public void setChecked(boolean checked) {
		this.checked = checked;
	}
	

	@Override
	public boolean equals(Object obj) {
		Permissions permission = (Permissions)obj;
		if(permission.getId().equals(this.id)){
			return true;
		}
		return false;
	}
	
	@Override
	public int hashCode() {
		return super.hashCode();
	}
}
